package smartcarpool.ui;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.support.v4.app.DialogFragment;
import android.os.Bundle;
import android.util.Log;
import android.widget.DatePicker;
import android.widget.EditText;

public class DatePickDialog extends DialogFragment implements OnDateSetListener {

	private EditText dateEdit;
	
	public DatePickDialog(EditText de) {
		super();
		this.dateEdit = de;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final Calendar c = Calendar.getInstance();
		int day = c.get(Calendar.DAY_OF_MONTH);
		int month = c.get(Calendar.MONTH);
		int year = c.get(Calendar.YEAR);

		return new DatePickerDialog(getActivity(), this, year, month, day);
	}
	
	@Override
	public void onDateSet(DatePicker arg0, int year, int month, int day) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, day);
		Log.d("Date Set", cal.toString());
		this.dateEdit.setText(String.format("%1$te.%1$tm.%1$tY", cal));
	}

}
